<?php

namespace app\console\model;

use think\Model;
use think\Request;

class AuthGroup extends Model
{
    // 状态分类
    protected function getStatusTextAttr($value, $data)
    {
        $status = [0 => '禁用', 1 => '启用'];

        return $status[$data['status']];
    }

    // 模式分类
    protected function getTypeTextAttr($value, $data)
    {
        $status = [1 => 'URL模式', 2 => '主菜单','0' => 0];

        return $status[$data['type']];
    }


    protected static function init()
    {
        // 编辑前
        self::event('before_update', function ($data) {

            $data->update_time = date('Y-m-d', time());
        });
    }

    // 权限处理
    public static function jurisdiction($id)
    {
        $data = Request::instance()->param();

        $checkId = implode(',', $data['checkId']);

        $status = self::where('id', $id)->update(['rules' => $checkId]);
        if ($status === false) return false;

        return true;
    }
}